//2009/08/25 00:48:13
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class CondorcetVoting
{
public:
    int winner(vector <string> v)
    {
        votes = v;
        N = votes[0].size();
        M = votes.size();
        for (int i=0; i<N; i++)
        {
            int temp = 0;
            for (int j=0; j<N; j++)
                if (isprefered(i,j))
                    temp++;
            if (temp == N-1)
                return i;
        }
        return -1;
    }
    bool isprefered(int x, int y)
    {
        int sum = 0;
        for (int i=0; i<M; i++)
        {
            if (votes[i][x] > votes[i][y])	sum ++;
            if (votes[i][x] < votes[i][y]) 	sum --;
        }
        return sum < 0;
    }
private:
    int N;
    int M;
    vector<string> votes;
};
